﻿class com.criticalmass.common.drawing.shapes.Star {
	var lineTo:Function;
	var moveTo:Function;
	var beginFill:Function;
	var endFill:Function;
	var clear:Function;
	var lineStyle:Function;
	var beginGradientFill:Function;
/**
* Draws a star using the Drawing API. This class must be attached to a movieclip in the library and exported for Actionscript
* You can draw unfilled or filled stars by changing which parameters are passed
* @param x x position of  fill
* @param y y position of  fill
* @param points number of points
* @param innerRadius innerRadius of fill :: number
* @param outerRadius outRadiusadius of fill :: number
* @param yRadius yRadius of fill. Will flatten out star :: number
* @param angle the length of each segment
* @param line lineStyle :: object
* @param col hex color of fill :: number or array [0x######,0x######]
* @param alpha alpha value of fill :: number or array [0x######,0x######]
* @param gradient type of gradient "linear" or "radial"
* @param ratios (optional :: default  [0,255]) - specifies the distribution of colors :: array [#,#];
* @param rot rotation of fill :: number or matrix object  {matrixType:"box",x:#,y:#,w:#,h:#,r:(#*(Math.PI/180))}
*/
	function drawStar(x, y, points, innerRadius, outerRadius, yRadius, startAngle, line, col, alpha, gradient, ratios, rot):Void {
		if (yRadius == undefined || yRadius == null) {
			//var innerYRadius = innerRadius;
			//var outerYRadius = outerRadius;
		}
		this.lineStyle(line.thickness, line.col, line.alpha);
		// if color is an object then allow for complex fills
		if (typeof col == "object") {
			if (typeof alpha != "object") {
				var alphas = [alpha, alpha];
			} else {
				var alphas = alpha;
			}
			if (ratios == undefined) {
				var ratios = [0, 0xff];
			}
			var sh = yRadius*.7;
			if (typeof rot != "object") {
				var matrix = {matrixType:"box", x:-sh, y:sh, w:outerRadius*2, h:outerRadius*4, r:rot*0.0174532925199433};
			} else {
				var matrix = rot;
			}
			if (gradient == "radial") {
				this.beginGradientFill("radial", col, alphas, ratios, matrix);
			} else {
				this.beginGradientFill("linear", col, alphas, ratios, matrix);
			}
		} else if (col != undefined) {
			this.beginFill(col, alpha);
		}
		var count = Math.abs(points);
		if (count>2) {
			// span of the sides
			var step = (Math.PI*2)/points;
			var halfStep = step/2;
			// convert start angle to radians
			var start = (startAngle/180)*Math.PI;
			this.moveTo(x+(Math.cos(start)*outerRadius), y-(Math.sin(start)*outerRadius));
			//draw the polygon
			for (var i = 0; i<=count; i++) {
				var dx = x+Math.cos(start+(step*i)-halfStep)*innerRadius;
				var dy = y-Math.sin(start+(step*i)-halfStep)*innerRadius;
				this.lineTo(dx, dy);
				var dx = x+Math.cos(start+(step*i))*outerRadius;
				var dy = y-Math.sin(start+(step*i))*outerRadius;
				this.lineTo(dx, dy);
			}
		}
		if (col != undefined) {
			this.endFill();
		}
	}
	/**
		* The classConstructed method ensures that the MovieClip Class is extended with this new method
		*/
	static function classConstruct(Void):Boolean {
		MovieClip.prototype.drawStar = Star.prototype.drawStar;
		return true;
	}
	static var classConstructed = classConstruct();
}
